package com.bajiao.service.system.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bajiao.common.constant.CacheConstant;
import com.bajiao.dto.system.AreaTreeDTO;
import com.bajiao.entity.system.Area;
import com.bajiao.mapper.system.AreaMapper;
import com.bajiao.service.system.IAreaService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 行政区划
 * @Author: FanJq
 * @Date: 2024-10-1011-17
 * @Version: V1.0
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {

    @Override
    @Cacheable(value = CacheConstant.AREA_SSX_LIST)
    public List<AreaTreeDTO> listShengShiXiang() {
        List<AreaTreeDTO> list = baseMapper.listShengShiXiang();
        list.forEach(e -> {
            if (e.getLevel() == 3) {
                e.setLeaf(true);
            }
        });
        return list;
    }

    @Override
    @Cacheable(value = CacheConstant.AREA_PID_LIST, key = "#pid")
    public List<Area> listByPid(String pid) {
        return baseMapper.listByPid(pid);
    }
}
